package org.jeecg.modules.demo.hd.controller;

import java.util.Arrays;
import javax.servlet.http.HttpServletRequest;

import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.config.shiro.IgnoreAuth;
import org.jeecg.modules.demo.hd.entity.AppYinsixieyi;
import org.jeecg.modules.demo.hd.service.IAppYinsixieyiService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

/**
 * @Description: app_yinsixieyi
 * @Author: jeecg-boot
 * @Date: 2025-02-09
 * @Version: V1.0
 */
@Api(tags = "协议管理")
@RestController
@RequestMapping("/hd/appYinsixieyi")
@Slf4j
public class AppYinsixieyiController extends JeecgController<AppYinsixieyi, IAppYinsixieyiService> {
    @Autowired
    private IAppYinsixieyiService appYinsixieyiService;

    /**
     * 分页列表查询
     *
     * @param appYinsixieyi
     * @param pageNo
     * @param pageSize
     * @param req
     * @return
     */
    @ApiOperation(value = "app_yinsixieyi-分页列表查询", notes = "app_yinsixieyi-分页列表查询")
    @GetMapping(value = "/list")
    public Result<IPage<AppYinsixieyi>> queryPageList(AppYinsixieyi appYinsixieyi,
                                                      @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                                      @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                      HttpServletRequest req) {
        QueryWrapper<AppYinsixieyi> queryWrapper = QueryGenerator.initQueryWrapper(appYinsixieyi, req.getParameterMap());
        Page<AppYinsixieyi> page = new Page<AppYinsixieyi>(pageNo, pageSize);
        IPage<AppYinsixieyi> pageList = appYinsixieyiService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

    /**
     * 添加
     *
     * @param appYinsixieyi
     * @return
     */
    @AutoLog(value = "app_yinsixieyi-添加")
    @ApiOperation(value = "app_yinsixieyi-添加", notes = "app_yinsixieyi-添加")
    @RequiresPermissions("hd:app_yinsixieyi:add")
    @PostMapping(value = "/add")
    public Result<String> add(@RequestBody AppYinsixieyi appYinsixieyi) {
        appYinsixieyiService.save(appYinsixieyi);
        return Result.OK("添加成功！");
    }


    @AutoLog(value = "查看隐私协议")
    @ApiOperation(value = "查看隐私协议", notes = "查看隐私协议")
    @GetMapping(value = "/query")
    @IgnoreAuth
    public Result<String> query() {
        return Result.OK("成功", appYinsixieyiService.queryOne());
    }


    @AutoLog(value = "查看用户协议")
    @ApiOperation(value = "查看用户协议", notes = "查看用户协议")
    @GetMapping(value = "/queryYonghu")
    @IgnoreAuth
    public Result<String> queryYonghu() {
        return Result.OK("成功", appYinsixieyiService.queryOne("1"));
    }

    @AutoLog(value = "查看注册协议")
    @ApiOperation(value = "查看注册协议", notes = "查看注册协议")
    @GetMapping(value = "/queryZhuce")
    @IgnoreAuth
    public Result<String> queryZhuce() {
        return Result.OK("成功", appYinsixieyiService.queryOne("2"));
    }

    @AutoLog(value = "关于我们")
    @ApiOperation(value = "关于我们", notes = "关于我们")
    @GetMapping(value = "/queryAbout")
    @IgnoreAuth
    public Result<String> queryAbout() {
        return Result.OK("成功", appYinsixieyiService.queryOne("3"));
    }


    /**
     * 编辑
     *
     * @param appYinsixieyi
     * @return
     */
    @AutoLog(value = "app_yinsixieyi-编辑")
    @ApiOperation(value = "app_yinsixieyi-编辑", notes = "app_yinsixieyi-编辑")
    @RequiresPermissions("hd:app_yinsixieyi:edit")
    @RequestMapping(value = "/edit", method = {RequestMethod.PUT, RequestMethod.POST})
    public Result<String> edit(@RequestBody AppYinsixieyi appYinsixieyi) {
        appYinsixieyiService.updateById(appYinsixieyi);
        return Result.OK("编辑成功!");
    }

    /**
     * 通过id删除
     *
     * @param id
     * @return
     */
    @AutoLog(value = "app_yinsixieyi-通过id删除")
    @ApiOperation(value = "app_yinsixieyi-通过id删除", notes = "app_yinsixieyi-通过id删除")
    @RequiresPermissions("hd:app_yinsixieyi:delete")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam(name = "id", required = true) String id) {
        appYinsixieyiService.removeById(id);
        return Result.OK("删除成功!");
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return
     */
    @AutoLog(value = "app_yinsixieyi-批量删除")
    @ApiOperation(value = "app_yinsixieyi-批量删除", notes = "app_yinsixieyi-批量删除")
    @RequiresPermissions("hd:app_yinsixieyi:deleteBatch")
    @DeleteMapping(value = "/deleteBatch")
    public Result<String> deleteBatch(@RequestParam(name = "ids", required = true) String ids) {
        this.appYinsixieyiService.removeByIds(Arrays.asList(ids.split(",")));
        return Result.OK("批量删除成功!");
    }

    /**
     * 通过id查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "app_yinsixieyi-通过id查询", notes = "app_yinsixieyi-通过id查询")
    @GetMapping(value = "/queryById")
    public Result<AppYinsixieyi> queryById(@RequestParam(name = "id", required = true) String id) {
        AppYinsixieyi appYinsixieyi = appYinsixieyiService.getById(id);
        if (appYinsixieyi == null) {
            return Result.error("未找到对应数据");
        }
        return Result.OK(appYinsixieyi);
    }
}
